
package com.netease.xone.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.FrameLayout;

import com.netease.pkgRelated.XoneConsts;
import com.netease.xone.R;
import com.netease.xone.fragment.FragmentImageBrowser;

public class ActivityImageBrowser extends ActivityX1Base {

    public static final String TAG = ActivityImageBrowser.class.getSimpleName();

    public static void startActivity(Context context, int index, int type, String value) {
        Intent intent = new Intent(context, ActivityImageBrowser.class);
        if(!(context instanceof Activity))
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(XoneConsts.EXTRA_DURATION, index);
        intent.putExtra(XoneConsts.EXTRA_OPERATE, type);
        intent.putExtra(XoneConsts.EXTRA_PATH, value);
        context.startActivity(intent);
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        FrameLayout linear = new FrameLayout(this);
        linear.setId(R.id.activity_image_container_id);
        setContentView(linear);
        int index = getIntent().getIntExtra(XoneConsts.EXTRA_DURATION, 0);
        int type = getIntent().getIntExtra(XoneConsts.EXTRA_OPERATE, FragmentImageBrowser.TYPE_IMAGE);
        String value = getIntent().getStringExtra(XoneConsts.EXTRA_PATH);
        
        if (null != findViewById(R.id.activity_image_container_id) && savedInstanceState == null) {
            Fragment fragment = null;
            
            fragment = FragmentImageBrowser.newInstance(index, type, value);
            getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.activity_image_container_id, fragment, TAG)
            .commit();
        }
    }
    
}
